#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int n;
  cin >> n;

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<vector<int>> f(n + 2, vector<int>(n + 2, -1));
  auto dfs = [&](auto &&dfs, int l, int r) -> int {
    if (l >= n && r >= n) {
      return f[l][r] = 0;
    }
    if (r >= n) {
      return f[l][r] = a[l];
    }
    if (f[l][r] != -1) {
      return f[l][r];
    }
    f[l][r] = max(a[l], a[r]) + dfs(dfs, r + 1, r + 2);
    f[l][r] = min(f[l][r], max(a[r], a[r + 1]) + dfs(dfs, l, r + 2));
    f[l][r] = min(f[l][r], max(a[l], a[r + 1]) + dfs(dfs, r, r + 2));
    return f[l][r];
  };
  cout << dfs(dfs, 0, 1) << '\n';

  auto get = [&](auto &&get, int l, int r) -> void {
    if (l >= n && r >= n) {
      return;
    }
    if (r >= n) {
      cout << l + 1 << '\n';
      return;
    }
    if (f[l][r] == max(a[l], a[r]) + f[r + 1][r + 2]) {
      cout << l + 1 << ' ' << r + 1 << '\n';
      get(get, r + 1, r + 2);
    } else if (f[l][r] == max(a[r], a[r + 1]) + f[l][r + 2]) {
      cout << r + 1 << ' ' << r + 2 << '\n';
      get(get, l, r + 2);
    } else {
      cout << l + 1 << ' ' << r + 2 << '\n';
      get(get, r, r + 2);
    }
  };
  get(get, 0, 1);
  return 0;
}